
#include <BGeoSphere>
#include <BViewer>

#include <BLight>
#include "member_BLight.h"

using namespace BWE;

#define member					(*(member_BLight*)_ptr)
#define member_allocate()		_ptr = new member_BLight(this)
#define member_release()		delete (member_BLight*)_ptr

BLight::BLight(Type type)
{
	member_allocate();
	this->setType(type);
	this->setAmbient(30, 30, 30);
	this->setDiffuse(255, 255, 255);
	this->setSpecular(128, 128, 128);
}
BLight::BLight(const BString& name, Type type)
{
	member_allocate();
	this->setName(name);
	this->setType(type);
	this->setAmbient(30, 30, 30);
	this->setDiffuse(255, 255, 255);
	this->setSpecular(128, 128, 128);
}
BLight::~BLight()
{
	member_release();
}

void BLight::setType(Type type)
{
	if (member.type != type)
	{
		member.type = type;
		emit(Signal_Fresh);
	}
}
BLight::Type BLight::type() const
{
	return member.type;
}

void BLight::setAmbient(BByte r, BByte g, BByte b, BByte a)
{
	setAmbient(BColor(r, g, b, a));
}
void BLight::setAmbient(const BColor& ambient)
{
	if (member.ambient != ambient)
	{
		member.ambient = ambient;
		member.ambientColor.r() = ambient.r() / 255.0f;
		member.ambientColor.g() = ambient.g() / 255.0f;
		member.ambientColor.b() = ambient.b() / 255.0f;
		member.ambientColor.a() = ambient.a() / 255.0f;
		emit(Signal_Fresh);
	}
}
const BColor& BLight::ambient() const
{
	return member.ambient;
}

void BLight::setDiffuse(BByte r, BByte g, BByte b, BByte a)
{
	setDiffuse(BColor(r, g, b, a));
}
void BLight::setDiffuse(const BColor& diffuse)
{
	if (member.diffuse != diffuse)
	{
		member.diffuse = diffuse;
		member.diffuseColor.r() = diffuse.r() / 255.0f;
		member.diffuseColor.g() = diffuse.g() / 255.0f;
		member.diffuseColor.b() = diffuse.b() / 255.0f;
		member.diffuseColor.a() = diffuse.a() / 255.0f;
		emit(Signal_Fresh);
	}
}
const BColor& BLight::diffuse() const
{
	return member.diffuse;
}

void BLight::setSpecular(BByte r, BByte g, BByte b, BByte a)
{
	setSpecular(BColor(r, g, b, a));
}
void BLight::setSpecular(const BColor& specular)
{
	if (member.specular != specular)
	{
		member.specular = specular;
		member.specularColor.r() = specular.r() / 255.0f;
		member.specularColor.g() = specular.g() / 255.0f;
		member.specularColor.b() = specular.b() / 255.0f;
		member.specularColor.a() = specular.a() / 255.0f;
		emit(Signal_Fresh);
	}
}
const BColor& BLight::specular() const
{
	return member.specular;
}

void BLight::setAttenuation(float attenuation)
{
	if (member.attenuation != attenuation)
	{
		member.attenuation = attenuation;
		emit(Signal_Fresh);
	}
}
float BLight::attenuation() const
{
	return member.attenuation;
}

void BLight::setAttenuation2(float attenuation2)
{
	if (member.attenuation2 != attenuation2)
	{
		member.attenuation2 = attenuation2;
		emit(Signal_Fresh);
	}
}
float BLight::attenuation2() const
{
	return member.attenuation2;
}

void BLight::setCutoff(float cutoff)
{
	if (member.cutoff != cutoff)
	{
		member.cutoff = cutoff;
		emit(Signal_Fresh);
	}
}
float BLight::cutoff() const
{
	return member.cutoff;
}

void BLight::setExponent(float exponent)
{
	if (member.exponent != exponent)
	{
		member.exponent = exponent;
		emit(Signal_Fresh);
	}
}
float BLight::exponent() const
{
	return member.exponent;
}

void BLight::setDirection(BReal x, BReal y, BReal z)
{
	member.direction.set(x, y, z);
}
void BLight::setDirection(const BVector& direction)
{
	if (member.direction != direction)
	{
		member.direction = direction;
		emit(Signal_Fresh);
	}
}
const BVector& BLight::direction() const
{
	return member.direction;
}

